package com.yc.vote.servlet;

import com.yc.vote.biz.TpRecordBiz;
import com.yc.vote.entity.TpUser;
import com.yc.vote.util.Utils;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "VoteServlet", value = "/vote")
public class VoteServlet extends HttpServlet {
    TpRecordBiz biz = new TpRecordBiz();

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String vid = request.getParameter("vid");
        String[] iids = request.getParameterValues("iids");
        TpUser myinfo = (TpUser) request.getSession().getAttribute("myinfo");
        String uid = myinfo.getId() + "";
        Utils.result("投票成功!", response, () -> biz.vote(vid, iids, uid));
    }
}
